<?php
/**
 * User:chendenan
 * Created On 2022/3/10 0010 23:09
 */
namespace app\common\lib\sms;

use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use think\facade\Log;

class AliSms
{

    /**
     * 阿里云发送短信验证码
     * 使用AK&SK初始化账号Client
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Dysmsapi Client
     */
    public static function createClient($accessKeyId, $accessKeySecret)
    {
        $config = new Config([
            // 您的AccessKey ID
            "accessKeyId" => confing("aliyun.access_key_id"),
            // 您的AccessKey Secret
            "accessKeySecret" => config("aliyun.access_key_secret")
        ]);
        // 访问的域名
        $config->endpoint = config("aliyun.host");
        return new Dysmsapi($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public static function main($args)
    {
        $client = self::createClient(confing("aliyun.access_key_id"), config("aliyun.access_key_secret"));
        $sendSmsRequest = new SendSmsRequest([
            "phoneNumbers" => "138****1380",
            "signName" => "test",
            "templateCode" => "132132",
            "templateParam" => "{\"name\":\"张三\",\"number\":\"15038****76\"}"
        ]);
        // 复制代码运行请自行打印 API 的返回值
        $client->sendSms($sendSmsRequest);
        Log::info("alisms-sendcode-result".);
    }
}

//$path = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor' . \DIRECTORY_SEPARATOR . 'autoload.php';
//if (file_exists($path)) {
//    require_once $path;
//}
//Sample::main(array_slice($argv, 1));